module.exports.plugin = (schame) => {
    schame.add({
      created: {
        type: Date,
        default: new Date
  
      },
      updated: {
        type: Date,
        default: new Date()
      }
    })
    
    schame.pre('save', (next) => {
      if (!this.created) {
        this.created = new Date()
      }
      this.updated = new Date()
      next()
    })
    if (!schame.options.toObject) {
      schame.options.toObject = {}
    }
    if (!schame.options.toJSON) {
      schame.options.toJSON = {}
    }
  
    /**
     * 转换
     * @param {*} doc 
     * @param {*} ret 
     * @param {*} options 
     */
    const transform = (doc, ret, options) => {
      ret.id = ret._id
      delete ret.__v
      delete ret._id
      return ret
    }
    schame.options.toObject.transform = transform
    schame.options.toJSON.transform = transform
  }